/*
 * Copyright (C) 2010-2011 sunjumper@163.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *  http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package mf.mfrpc.util;

import java.lang.reflect.Method;
import mfinder.util.MethodUtil;

/**
 * 生成方法路径的工具类。
 */
public class LocationUtil {

    /** 方法分隔符, http请求符号不能为 # ? */
    public static final char MARK = '!';

    /** 后缀分隔符 */
    private static final char SEP = '.';

    /**
     * 获取请求方法的实际地址.
     *
     * @param url 请求地址。
     * @param method 请求方法。
     * 
     * @return 请求方法的地址。
     */
    public static String locate(String url, Method method) {
        int lastpoint = url.lastIndexOf(SEP);
        return lastpoint == -1
                ? url + MARK + MethodUtil.getMethodInfo(method)
                : url.substring(0, lastpoint) + MARK + MethodUtil.getMethodInfo(method) + url.substring(lastpoint);
    }
}
